<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function main(config) {
        //const dbHost = config && config.db && config.db.host;
        //通过可选链操作符 ?.  避免层层判断
        const dbHost = config?.db?.host;
        console.log(dbHost);
    }


    main({
        db: {
            host: '192.168.108.1',
            username: 'root'
        },
        cache: {
            host: '192.168.108.1',
            username: 'admin'
        }
    })
</script>
</body>
</html>
